package response

import (
	"github.com/gin-gonic/gin"
	"net/http"
)

type Response struct {
	ResultCode int
	Data       interface{}
	Msg        string
}

const (
	ERROR         = 500
	SUCCESS       = 200
	UNLOGIN       = 412
	TYPE_DISMATCH = 400
)

func Result(code int, data interface{}, msg string, c *gin.Context) {
	c.JSON(http.StatusOK, Response{
		code,
		data,
		msg,
	})
}

func Ok(c *gin.Context) {
	Result(SUCCESS, map[string]interface{}{}, "操作成功", c)
}

func OkWithMsg(c *gin.Context, msg string) {
	Result(SUCCESS, map[string]interface{}{}, msg, c)
}

func OkWithData(c *gin.Context, data interface{}) {
	Result(SUCCESS, data, "操作成功", c)
}

func OkWithDetail(c *gin.Context, data interface{}, msg string) {
	Result(SUCCESS, data, msg, c)
}

func Fail(c *gin.Context) {
	Result(ERROR, map[string]interface{}{}, "操作失败", c)
}
func FailWithMsg(c *gin.Context, msg string) {
	Result(ERROR, map[string]interface{}{}, msg, c)
}
func FailWithData(c *gin.Context, data interface{}) {
	Result(ERROR, data, "操作失败", c)
}

func FailWithDetail(c *gin.Context, data interface{}, msg string) {
	Result(ERROR, data, msg, c)
}

func UnLogin(c *gin.Context, data interface{}) {
	Result(UNLOGIN, data, "未登录", c)
}
